home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / m4-1_0_3.lha / m4-1.0.3 / m4.info-1 (.txt) < prev    next >
GNU Info File  |  1992-12-19  |  50KB  |  1,081 lines

  1. This is Info file m4.info, produced by Makeinfo-1.47 from the input
  2. file ./m4.texinfo.
  3.    This file documents the GNU m4 utility.
  4.    Copyright (C) 1989-1992 Free Software Foundation, Inc.
  5.    Permission is granted to make and distribute verbatim copies of this
  6. manual provided the copyright notice and this permission notice are
  7. preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the entire resulting derived work is distributed under the terms
  11. of a permission notice identical to this one.
  12.    Permission is granted to copy and distribute translations of this
  13. manual into another language, under the above conditions for modified
  14. versions.
  15. File: m4.info,  Node: Top,  Next: Intro,  Prev: (dir),  Up: (dir)
  16.    This file documents GNU `m4', which is a simple macroprocessor.  It
  17. has been originally written by Rene' Seindal, from Denmark.
  18. * Menu:
  19. * Intro::                       Introduction to m4
  20. * Manual::                      How to use this manual
  21. * Bugs::                        Reporting bugs in m4
  22. * Invoking m4::                 How to run the program
  23. * Syntax::                      Lexical and syntactic conventions
  24. * Macros::                      How to invoke macros
  25. * Definitions::                 How to define new macros
  26. * Conditionals::                Conditionals and loops
  27. * Debugging::                   How to debug macros and input
  28. * Input Control::               Input control
  29. * File Inclusion::              File inclusion
  30. * Diversions::                  Diverting and undiverting output
  31. * Text handling::               Macros for text handling
  32. * Arithmetic::                  Macros for doing arithmetic
  33. * Unix commands::               Macros for running Unix commands
  34. * Miscellaneous::               Miscellaneous built-in macros
  35. * Compatibility::               Compatibility with other versions of m4
  36. * Concept Index::        Index for many concepts
  37. * Macro Index::            Index for all m4 macros
  38.  -- The Detailed Node Listing --
  39. Lexical and syntactic conventions
  40. * Names::                       Macro names.
  41. * Quoted strings::              Quoting input to m4.
  42. * Other tokens::                Other kinds of input tokens.
  43. * Comments::                    Comments in m4 input.
  44. How to invoke macros
  45. * Invocation::                  Macro invocation
  46. * Macro Arguments::             Macro arguments.
  47. * Quoting Arguments::           On Quoting Arguments to macros.
  48. * Macro expansion::             Expanding macros.
  49. How to define new macros
  50. * Define::                      Defining a new macro
  51. * Arguments::                   Arguments to macros
  52. * Pseudo Arguments::            Pseudo arguments to macros
  53. * Undefine::                    Deleting a macro
  54. * Defn::                        Renaming macros
  55. * Pushdef::                     Temporarily redefining macros
  56. * Indir::                       Indirect call of macros
  57. * Builtin::                     Indirect call of built-ins
  58. Conditionals, loops and recursion
  59. * Ifdef::                       Testing if a macro is defined
  60. * Ifelse::                      If-else construct, or multibranch
  61. * Loops::                       Loops and recursion in m4
  62. How to debug macros and input
  63. * Dumpdef::                     Displaying macro definitions
  64. * Trace::                       Tracing macro calls
  65. * Debug Levels::                Controlling debugging output
  66. * Debug Output::                Saving debugging output
  67. Input control
  68. * Dnl::                         Deleting whitespace in input
  69. * Changequote::                 Changing the quote characters
  70. * Changecom::                   Changing the comment delimiters
  71. * M4wrap::                      Saving input until end of input
  72. File inclusion
  73. * Include::                     Including named files
  74. * Search Path::                 Searching for include files
  75. Diverting and undiverting output
  76. * Divert::                      Diverting output
  77. * Undivert::                    Undiverting output
  78. * Divnum::                      Diversion numbers
  79. * Cleardiv::                    Discarding diverted text
  80. Macros for text handling
  81. * Len::                         Calculating length of strings
  82. * Index::                       Searching for substrings
  83. * Regexp::                      Searching for regular expressions
  84. * Substr::                      Extracting substrings
  85. * Translit::                    Translating characters
  86. * Patsubst::                    Substituting text by regular expression
  87. * Format::                      Formatting strings (printf-like)
  88. Macros for doing arithmetic
  89. * Incr::                        Decrement and increment operators
  90. * Eval::                        Evaluating integer expressions
  91. Running Unix commands
  92. * Syscmd::                      Executing simple commands
  93. * Esyscmd::                     Reading the output of commands
  94. * Sysval::                      Exit codes
  95. * Maketemp::                    Making names for temporary files
  96. Miscellaneous built-in macros
  97. * Errprint::                    Printing error messages
  98. * M4exit::                      Exiting from m4
  99. Compatibility with other versions of `m4'
  100. * Extensions::                  Extensions in GNU m4
  101. * Incompatibilities::           Facilities in System V m4 not in GNU m4
  102. * Other Incompat::              Other incompatibilities
  103. File: m4.info,  Node: Intro,  Next: Manual,  Prev: Top,  Up: Top
  104. Introduction to `m4'
  105. ********************
  106.    `m4' is a macro processor, in the sense that in copies its input to
  107. the output, expanding macros as it goes.  Macros are either built-in or
  108. user-defined, and can take any number of arguments.  Besides just doing
  109. macro expansion, `m4' has built-in functions for including named files,
  110. running Unix commands, doing integer arithmetic, manipulating text in
  111. various ways, recursion, etc...
  112.    `m4' can be used either as a front-end to a compiler, or as a macro
  113. processor in its own right.
  114.    GNU `m4' is mostly compatible with the System V, Release 3 version,
  115. except for some minor differences.  *Note Compatibility:: for more
  116. details.
  117. File: m4.info,  Node: Manual,  Next: Bugs,  Prev: Intro,  Up: Top
  118. Using this manual
  119. *****************
  120.    This manual contains a number of examples of `m4' input and output,
  121. and a simple notation is used to distinguish input, output and error
  122. messages from `m4'.  Examples are set out from the normal text, and
  123. shown in a fixed width font, like this
  124.      This is an example of an example!
  125.    To distinguish input from output, all output from `m4' is prefixed
  126. by the string `=>', and all error messages by the string `error-->'. 
  127.      Example of input line
  128.      =>Output line from m4
  129.      error-->and an error message
  130.    As each of the predefined macros in `m4' is described, a prototype
  131. call of the macro will be shown, giving descriptive names to the
  132. arguments, e.g.,
  133.      regexp(STRING, REGEXP, opt REPLACEMENT)
  134.    All macro arguments in `m4' are strings, but some are given special
  135. interpretation, e.g., as numbers, filenames, regular expressions, etc.
  136.    The `opt' before the third argument shows that this argument is
  137. optional--if it is left out, it is taken to be the empty string.  An
  138. ellipsis (`...') last in the argument list indicates that any number of
  139. arguments may follow.
  140. File: m4.info,  Node: Bugs,  Next: Invoking m4,  Prev: Manual,  Up: Top
  141. Problems and bugs
  142. *****************
  143.    If you have problems with GNU `m4' or think you've found a bug,
  144. please report it.  Before reporting a bug, make sure you've actually
  145. found a real bug.  Carefully reread the documentation and see if it
  146. really says you can do what you're trying to do.  If it's not clear
  147. whether you should be able to do something or not, report that too; it's
  148. a bug in the documentation!
  149.    Before reporting a bug or trying to fix it yourself, try to isolate
  150. it to the smallest possible input file that reproduces the problem. 
  151. Then send us the input file and the exact results `m4' gave you.  Also
  152. say what you expected to occur; this will help us decide whether the
  153. problem was really in the documentation.
  154.    Once you've got a precise problem, send e-mail to (Internet)
  155. `bug-gnu-utils@prep.ai.mit.edu' or (UUCP)
  156. `mit-eddie!prep.ai.mit.edu!bug-gnu-utils'.  Please include the version
  157. number of `m4' you are using.  You can get this information with the
  158. command `m4 -V /dev/null'.
  159.    Non-bug suggestions are always welcome as well.  If you have
  160. questions about things that are unclear in the documentation or are
  161. just obscure features, please report them too.
  162. File: m4.info,  Node: Invoking m4,  Next: Syntax,  Prev: Bugs,  Up: Top
  163. Invoking `m4'
  164. *************
  165.    The format of the `m4' command is:
  166.      `m4' [OPTIONS] [MACRO-DEFINITIONS] [INPUT-FILES]
  167.    All options begin with `-', or if long option names are used, with a
  168. `--'.  A long option name need not be written completely, and
  169. unambigous prefix is sufficient.  `m4' understands the following
  170. options:
  171. `--version'
  172.      Print the version number of the program.  To see only the version
  173.      number, use the command `m4 -V /dev/null'.
  174. `--no-gnu-extensions'
  175.      Suppress all the extensions made in this implementation, compared
  176.      to the System V version.  For a list of these, *note
  177.      Compatibility::..
  178. `-dFLAGS'
  179. `--debug FLAGS'
  180.      Set the debug-level according to the flags FLAGS.  The debug-level
  181.      controls the format and amount of information presented by the
  182.      debugging functions.  *Note Debug Levels:: for more details on the
  183.      format and meaning of FLAGS.
  184. `-lNUM'
  185. `--arglength NUM'
  186.      Restrict the size of the output generated by macro tracing.  *Note
  187.      Debug Levels:: for more details.
  188. `-oFILE'
  189. `--erroroutput FILE'
  190.      Redirect debug and trace output to the named file.  Error messages
  191.      are still printed on the standard error output.  *Note Debug
  192.      Output:: for more details.
  193. `-IDIR'
  194. `--include DIR'
  195.      Make `m4' search DIR for included files that are not found in the
  196.      current working directory.  *Note Search Path:: for more details.
  197. `--interactive'
  198.      Makes this invocation of `m4' interactive.  This means that all
  199.      output will be unbuffered, and interrupts will be ignored.
  200. `--synclines'
  201.      Generate synchronisation lines, for use by the C preprocessor or
  202.      other similar tools.  This is useful, for example, when `m4' is
  203.      used as a front end to a compiler.  Source file name and line
  204.      number information is conveyed by lines of the form `#line LINENUM
  205.      "FILENAME"', which are inserted as needed into the middle of the
  206.      input (but always on complete lines per themselves).  Such lines
  207.      mean that the following line originated or was expanded from the
  208.      contents of input file FILENAME at line LINENUM.  The `"FILENAME"'
  209.      part is often omitted when the file name did not change from the
  210.      previous synchronisation line.
  211. `-HN'
  212. `--hashsize N'
  213.      Make the internal hash table for symbol lookup be N entries big.
  214.      The number should be prime.  The default is 509 entries.  It
  215.      should not be necessary to increase this value, unless you define
  216.      an excessive number of macros.
  217. `-NN'
  218. `--diversions N'
  219.      Allow for up to N diversions to be used at the same time.  The
  220.      default is 10 diversions.
  221. `--quiet'
  222. `--silent'
  223.      Suppress warnings about missing or superflous arguments in macro
  224.      calls.
  225.      These options are present for compatibility with System V `m4', but
  226.      do nothing in this implementation.
  227.    Macro definitions and deletions can be made on the command line, by
  228. using the `-D' and `-U' options.  They have the following format:
  229. `-DNAME'
  230. `-DNAME=VALUE'
  231. `--define NAME'
  232. `--define NAME=VALUE'
  233.      This enters NAME into the symbol table, before any input files are
  234.      read.  If `=VALUE' is missing, the value is taken to be the empty
  235.      string.  The VALUE can be any string, and the macro can be defined
  236.      to take arguments, just as if it was defined from within the input.
  237. `-UNAME'
  238. `--undefine NAME'
  239.      This deletes any predefined meaning NAME might have.  Obviously,
  240.      only predefined macros can be deleted in this way.
  241. `-tNAME'
  242. `--trace NAME'
  243.      This enters NAME into the symbol table, as undefined but traced.
  244.      The macro will consequently be traced from the point it is defined.
  245.    The remaining arguments on the command line are taken to be input
  246. file names.  If no names are present, the standard input is read.  A
  247. file name of `-' is taken to mean the standard input.
  248.    The input files are read in the sequence given.  The standard input
  249. can only be read once, so the filename `-' should only appear once on
  250. the command line.
  251. File: m4.info,  Node: Syntax,  Next: Macros,  Prev: Invoking m4,  Up: Top
  252. Lexical and syntactic conventions
  253. *********************************
  254.    As `m4' reads its input, it separates it into "tokens".  A token is
  255. either a name, a quoted string, or any single character, that is not a
  256. part of either a name or a string.  Input to `m4' can also contain
  257. comments.
  258. * Menu:
  259. * Names::                       Macro names.
  260. * Quoted strings::              Quoting input to m4.
  261. * Other tokens::                Other kinds of input tokens.
  262. * Comments::                    Comments in m4 input.
  263. File: m4.info,  Node: Names,  Next: Quoted strings,  Prev: Syntax,  Up: Syntax
  264. Names
  265. =====
  266.    A name is any sequence of letters, digits, and the character `_'
  267. (underscore), where the first character is not a digit.  If a name has a
  268. macro definition, it will be subject to macro expansion (*note
  269. Macros::. for more details).
  270.    Examples of legal names are: `foo', `_tmp', and `name01'.
  271. File: m4.info,  Node: Quoted strings,  Next: Other tokens,  Prev: Names,  Up: Syntax
  272. Quoted strings
  273. ==============
  274.    A quoted string is a sequence of characters surrounded by the quotes
  275. ``' and `'', where the number of start and end quotes within the string
  276. balances.  The value of a string token is the text, with one level of
  277. quotes stripped off.  Thus
  278.      `'
  279.    is the empty string, and
  280.      ``quoted''
  281.    is the string
  282.      `quoted'
  283.    The quote characters can be changed at any time, using the built-in
  284. macro `changequote'.  *Note Changequote:: for more information.
  285. File: m4.info,  Node: Other tokens,  Next: Comments,  Prev: Quoted strings,  Up: Syntax
  286. Other tokens
  287. ============
  288.    Any character, that is neither a part of a name, nor of a quoted
  289. string, is a token by itself.
  290. File: m4.info,  Node: Comments,  Prev: Other tokens,  Up: Syntax
  291. Comments
  292. ========
  293.    Comments in `m4' are normally delimited by the characters `#' and
  294. newline.  All characters between the comment delimiters are ignored,
  295. but the entire comment (including the delimiters) is passed through to
  296. the output--comments are *not* discarded by `m4'.
  297.    Comments cannot be nested, so the first newline after a `#' ends the
  298. comment.  The begin comment character can be included in the input by
  299. quoting it.
  300.    The comment delimiters can be changed to any string at any time,
  301. using the built-in macro `changecom'.  *Note Changecom:: for more
  302. information.
  303. File: m4.info,  Node: Macros,  Next: Definitions,  Prev: Syntax,  Up: Top
  304. How to invoke macros
  305. ********************
  306.    This chapter covers macro invocation, macro arguments and how macro
  307. expansion is treated.
  308. * Menu:
  309. * Invocation::                  Macro invocation
  310. * Macro Arguments::             Macro arguments.
  311. * Quoting Arguments::           On Quoting Arguments to macros.
  312. * Macro expansion::             Expanding macros.
  313. File: m4.info,  Node: Invocation,  Next: Macro Arguments,  Prev: Macros,  Up: Macros
  314. Macro invocation
  315. ================
  316.    Macro invocations has one of the forms
  317.      name
  318. which is a macro invocation without any arguments, or
  319.      name(arg1, arg2, ..., argN)
  320. which is a macro invocation with N arguments.  Macros can have any
  321. number of arguments.  All arguments are strings, but different macros
  322. might interpret the arguments in different ways.
  323.    The opening parenthesis *must* follow the NAME directly, with no
  324. spaces in between.  If it does not, the macro is called with no
  325. arguments at all.
  326.    For a macro call to have no arguments, the parentheses *must* be
  327. left out.  The macro call
  328.      name()
  329. is a macro call with one argument, which is the empty string, not a call
  330. with no arguments.
  331. File: m4.info,  Node: Macro Arguments,  Next: Quoting Arguments,  Prev: Invocation,  Up: Macros
  332. Macro arguments
  333. ===============
  334.    When a name is seen, and it has a macro definition, it will be
  335. expanded as a macro.
  336.    If the name is followed by an opening parenthesis, the arguments
  337. will be collected before the macro is called.  If too few arguments are
  338. supplied, the missing arguments are taken to be the empty string.  If
  339. there are too many arguments, the excess arguments are ignored.
  340.    Normally `m4' will issue warnings if a built-in macro is called with
  341. an inappropriate number of arguments, but it can be suppressed with the
  342. `-Q' command line option.  For user defined macros, there is no check
  343. of the number of arguments given.
  344.    Macros are expanded normally during argument collection, and whatever
  345. commas, quotes and parentheses that might show up in the resulting
  346. expanded text will serve to define the arguments as well.  Thus, if FOO
  347. expands to `,b,c', the macro call
  348.      bar(a foo,d)
  349.    is a macro call with four arguments, which are `a ', `b', `c' and
  350. File: m4.info,  Node: Quoting Arguments,  Next: Macro expansion,  Prev: Macro Arguments,  Up: Macros
  351. Quoting macro arguments
  352. =======================
  353.    Each argument has leading unquoted whitespace removed.  Within each
  354. argument, all unquoted parentheses must match.  For example, if FOO is
  355. a macro,
  356.      foo(() (`(') `(')
  357.    is a macro call, with one argument, whose value is `() (() ('.
  358.    It is common practice to quote all arguments to macros, unless you
  359. are sure you want the arguments expanded.  Thus, in the above example
  360. with the parentheses, the `right' way to do it is like this:
  361.      foo(`() (() (')
  362.    It is, however, in certain cases necessary to leave out quotes for
  363. some arguments, and there is nothing wrong in doing it.  It just makes
  364. life a bit harder, if you are not careful.
  365. File: m4.info,  Node: Macro expansion,  Prev: Quoting Arguments,  Up: Macros
  366. Macro expansion
  367. ===============
  368.    When the arguments, if any, to a macro call have been collected, the
  369. macro is expanded, and the expansion text is pushed back onto the input
  370. (unquoted), and reread.  The expansion text from one macro call might
  371. therefore result in more macros being called, if the calls are included,
  372. completely or partially, in the first macro calls' expansion.
  373.    Taking a very simple example, if FOO expands to `bar', and BAR
  374. expands to `Hello world', the input
  375.      foo
  376. will expand first to `bar', and when this is reread and expanded, into
  377. `Hello world'.
  378. File: m4.info,  Node: Definitions,  Next: Conditionals,  Prev: Macros,  Up: Top
  379. How to define new macros
  380. ************************
  381.    Macros can be defined, redefined and deleted in several different
  382. ways. Also, it is possible to redefine a macro, without losing a
  383. previous value, which can be brought back at a later time.
  384. * Menu:
  385. * Define::                      Defining a new macro
  386. * Arguments::                   Arguments to macros
  387. * Pseudo Arguments::            Pseudo arguments to macros
  388. * Undefine::                    Deleting a macro
  389. * Defn::                        Renaming macros
  390. * Pushdef::                     Temporarily redefining macros
  391. * Indir::                       Indirect call of macros
  392. * Builtin::                     Indirect call of built-ins
  393. File: m4.info,  Node: Define,  Next: Arguments,  Prev: Definitions,  Up: Definitions
  394. Defining a macro
  395. ================
  396.    The normal way to define or redefine macros is to use the built-in
  397. `define':
  398.      define(NAME, EXPANSION)
  399. which defines NAME to expand to EXPANSION.
  400.    The expansion of `define' is void.
  401.    The following example defines the macro FOO to expand to the text
  402. `Hello World.'.
  403.      define(`foo', `Hello world.')
  404.      =>
  405.      foo
  406.      =>Hello world.
  407.    The empty line in the output is there because the newline is not a
  408. part of the macro definition, and it is consequently copied to the
  409. output. This can be avoided by use of the macro `dnl' (*note Dnl::. for
  410. details).
  411. File: m4.info,  Node: Arguments,  Next: Pseudo Arguments,  Prev: Define,  Up: Definitions
  412. Arguments to macros
  413. ===================
  414.    Macros can have arguments.  The Nth argument is denoted by `$n' in
  415. the expansion text, and is replaced by the Nth actual argument, when
  416. the macro is expanded.  Here is a example of a macro with two
  417. arguments.  It simply exchanges the order of the two arguments.
  418.      define(`exch', `$2, $1')
  419.      =>
  420.      exch(arg1, arg2)
  421.      =>arg2, arg1
  422.    This can be used, for example, if you like the arguments to `define'
  423. to be reversed.
  424.      define(`exch', `$2, $1')
  425.      =>
  426.      define(exch(``expansion text'', ``macro''))
  427.      =>
  428.      macro
  429.      =>expansion text
  430.    For an explanation of the double quotes, *note Quoting Arguments::..
  431.    GNU `m4' allows the number following the `$' to consist of one or
  432. more digits, allowing macros to have any number of arguments.  This is
  433. not so in Unix implementations of `m4', which only recognize one digit.
  434.    As a special case, the zero'th argument, `$0', is always the name of
  435. the macro being expanded.
  436.      define(`test', ``Macro name: $0'')
  437.      =>
  438.      test
  439.      =>Macro name: test
  440.    If you want quoted text to appear as part of the expansion text,
  441. remember that quotes can be nested in quoted strings.  Thus, in
  442.      define(`foo', `This is macro `foo'.')
  443.      =>
  444.      foo
  445.      =>This is macro foo.
  446. The `foo' in the expansion text is *not* expanded, since it is a quoted
  447. string, and not a name.
  448. File: m4.info,  Node: Pseudo Arguments,  Next: Undefine,  Prev: Arguments,  Up: Definitions
  449. Special arguments to macros
  450. ===========================
  451.    There is a special notation for the number of actual arguments
  452. supplied, and for all the actual arguments.
  453.    The number of actual arguments in a macro call is denoted by `$#' in
  454. the expansion text.  Thus, a macro to display the number of arguments
  455. given can be
  456.      define(`nargs', `$#')
  457.      =>
  458.      nargs
  459.      =>0
  460.      nargs()
  461.      =>1
  462.      nargs(arg1, arg2, arg3)
  463.      =>3
  464.    The notation `$*' can be used in the expansion text to denote all
  465. the actual arguments, unquoted, with commas in between.  For example
  466.      define(`echo', `$*')
  467.      =>
  468.      echo(arg1,    arg2, arg3 , arg4)
  469.      =>arg1,arg2,arg3 ,arg4
  470.    Often each argument should be quoted, and the notation `$@' handles
  471. that.  It is just like `$*', except that it quotes each argument. A
  472. simple example of that is:
  473.      define(`echo', `$@')
  474.      =>
  475.      echo(arg1,    arg2, arg3 , arg4)
  476.      =>arg1,arg2,arg3 ,arg4
  477.    Where did the quotes go?  Of course, they were eaten, when the
  478. expanded text were reread by `m4'.  To show the difference, try
  479.      define(`echo1', `$*')
  480.      =>
  481.      define(`echo2', `$@')
  482.      =>
  483.      define(`foo', `This is macro `foo'.')
  484.      =>
  485.      echo1(foo)
  486.      =>This is macro This is macro foo..
  487.      echo2(foo)
  488.      =>This is macro foo.
  489.    If you don't understand this, *note Trace::..
  490.    A `$' sign in the expansion text, that is not followed by anything
  491. `m4' understands, is simply copied to the macro expansion, as any other
  492. text is.
  493.      define(`foo', `$$$ hello $$$')
  494.      =>
  495.      foo
  496.      =>$$$ hello $$$
  497.    If you want a macro to expand to something like `$12', put a pair of
  498. quotes after the `$'.  This will prevent `m4' from interpreting the `$'
  499. sign as a reference to an argument.
  500. File: m4.info,  Node: Undefine,  Next: Defn,  Prev: Pseudo Arguments,  Up: Definitions
  501. Deleting a macro
  502. ================
  503.    A macro definition can be removed with `undefine':
  504.      undefine(NAME)
  505. which removes the macro NAME.  The macro name must necessarily be
  506. quoted, since it will be expanded otherwise.
  507.    The expansion of `undefine' is void.
  508.      foo
  509.      =>foo
  510.      define(`foo', `expansion text')
  511.      =>
  512.      foo
  513.      =>expansion text
  514.      undefine(`foo')
  515.      =>
  516.      foo
  517.      =>foo
  518.    It is not an error for NAME to have no macro definition.  In that
  519. case, `undefine' does nothing.
  520. File: m4.info,  Node: Defn,  Next: Pushdef,  Prev: Undefine,  Up: Definitions
  521. Renaming macros
  522. ===============
  523.    It is possible to rename an already defined macro.  To do this, you
  524. need the built-in `defn':
  525.      defn(NAME)
  526. which expands to the *quoted definition* of NAME.  If the argument is
  527. not a defined macro, the expansion is void.
  528.    If NAME is a user-defined macro, the quoted definition is simply the
  529. quoted expansion text.  If, instead, NAME is a built-in, the expansion
  530. is a special token, which points to the built-in's internal definition.
  531.  This token is only meaningful as the second argument to `define' (and
  532. `pushdef'), and is ignored in any other context.
  533.    Its normal use is best understood through an example, which shows
  534. how to rename `undefine' to `zap':
  535.      define(`zap', defn(`undefine'))
  536.      =>
  537.      zap(`undefine')
  538.      =>
  539.      undefine(`zap')
  540.      =>undefine(zap)
  541.    In this way, `defn' can be used to copy macro definitions, and also
  542. definitions of built-in macros.  Even if the original macro is removed,
  543. the other name can still be used to access the definition.
  544. File: m4.info,  Node: Pushdef,  Next: Indir,  Prev: Defn,  Up: Definitions
  545. Temporarily redefining macros
  546. =============================
  547.    It is possible to redefine a macro temporarily, reverting to the
  548. previous definition at a later time. This is done with the built-ins
  549. `pushdef' and `popdef':
  550.      pushdef(NAME, EXPANSION)
  551.      popdef(NAME)
  552. which are quite analogous to `define' and `undefine'.
  553.    These macros work in a stack-like fashion.  A macro is temporarily
  554. redefined with `pushdef', which replaces an existing definition of
  555. NAME, while saving the previous definition, before the new one is
  556. installed.  If there is no previous definition, `pushdef' behaves
  557. exactly like `define'.
  558.    If a macro has several definitions (of which only one is accessible),
  559. the topmost definition can be removed with `popdef'. If there is no
  560. previous definition, `popdef' does nothing.
  561.      define(`foo', `Expansion one.')
  562.      =>
  563.      foo
  564.      =>Expansion one.
  565.      pushdef(`foo', `Expansion two.')
  566.      =>
  567.      foo
  568.      =>Expansion two.
  569.      popdef(`foo')
  570.      =>
  571.      foo
  572.      =>Expansion one.
  573.      popdef(`foo')
  574.      =>
  575.      foo
  576.      =>foo
  577.    If a macro with several definitions is redefined with `define', the
  578. topmost definition is *replaced* with the new definition.  If it is
  579. removed with `undefine', *all* the definitions are removed, and not
  580. only the topmost one.
  581.      define(`foo', `Expansion one.')
  582.      =>
  583.      foo
  584.      =>Expansion one.
  585.      pushdef(`foo', `Expansion two.')
  586.      =>
  587.      foo
  588.      =>Expansion two.
  589.      define(`foo', `Second expansion two.')
  590.      =>
  591.      foo
  592.      =>Second expansion two.
  593.      undefine(`foo')
  594.      =>
  595.      foo
  596.      =>foo
  597.    It is possible to temporarily redefine a built-in with `pushdef' and
  598. `defn'.
  599. File: m4.info,  Node: Indir,  Next: Builtin,  Prev: Pushdef,  Up: Definitions
  600. Indirect call of macros
  601. =======================
  602.    Any macro can be called indirectly with `indir':
  603.      indir(NAME, ...)
  604. which results in a call to the macro NAME, which is passed the rest of
  605. the arguments.  This can be used to call macros with "illegal" names
  606. (`define' allows such names to be defined):
  607.      define(`$$internal$macro', `Internal macro (name `$0')')
  608.      =>
  609.      $$internal$macro
  610.      =>$$internal$macro
  611.      indir(`$$internal$macro')
  612.      =>Internal macro (name $$internal$macro)
  613.    The point is, here, that larger macro packages can have private
  614. macros defined, that will not be called by accident.  They can *only* be
  615. called through the built-in `indir'.
  616. File: m4.info,  Node: Builtin,  Prev: Indir,  Up: Definitions
  617. Indirect call of built-ins
  618. ==========================
  619.    Built-in macros can be called indirectly with `built-in':
  620.      builtin(NAME, ...)
  621. which results in a call to the built-in NAME, which is passed the rest
  622. of the arguments.  This can be used, if NAME has been given another
  623. definition that has covered the original.
  624. File: m4.info,  Node: Conditionals,  Next: Debugging,  Prev: Definitions,  Up: Top
  625. Conditionals, loops and recursion
  626. *********************************
  627.    Macros, expanding to plain text, perhaps with arguments, are not
  628. quite enough.  We would like to have macros expand to different things,
  629. based on decisions taken at run-time.  E.g., we need some kind of
  630. conditionals. Also, we would like to have some kind of loop construct,
  631. so we could do something a number of times, or while some condition is
  632. true.
  633. * Menu:
  634. * Ifdef::                       Testing if a macro is defined
  635. * Ifelse::                      If-else construct, or multibranch
  636. * Loops::                       Loops and recursion in m4
  637. File: m4.info,  Node: Ifdef,  Next: Ifelse,  Prev: Conditionals,  Up: Conditionals
  638. Testing macro definitions
  639. =========================
  640.    There are two different built-in conditionals in `m4'.  The first is
  641. `ifdef':
  642.      ifdef(NAME, STRING-1, opt STRING-2)
  643. which makes it possible to test whether a macro is defined or not.  If
  644. NAME is defined as a macro, `ifdef' expands to STRING-1, otherwise to
  645. STRING-2.  If STRING-2 is omitted, it is taken to be the empty string
  646. (according to the normal rules).
  647.      ifdef(`foo', ``foo' is defined', ``foo' is not defined')
  648.      =>foo is not defined
  649.      define(`foo', `')
  650.      =>
  651.      ifdef(`foo', ``foo' is defined', ``foo' is not defined')
  652.      =>foo is defined
  653. File: m4.info,  Node: Ifelse,  Next: Loops,  Prev: Ifdef,  Up: Conditionals
  654. Comparing strings
  655. =================
  656.    The other conditional, `ifelse', is much more powerful.  It can be
  657. used as a way to introduce a long comment, as an if-else construct, or
  658. as a multibranch, depending on the number of arguments supplied:
  659.      ifelse(COMMENT)
  660.      ifelse(STRING-1, STRING-2, EQUAL, opt NOT-EQUAL)
  661.      ifelse(STRING-1, STRING-2, EQUAL, ...)
  662. Used with only one argument, the `ifelse' simply discards it and
  663. produces no output.  This is a common `m4' idiom for introducing a
  664. block comment, as an alternative to repeatedly using `dnl'.  This
  665. special usage is recognized by GNU `m4', so that in this case, the
  666. warning about missing arguments is never triggered.
  667.    If called with three or four arguments, `ifelse' expands into EQUAL,
  668. if STRING-1 and STRING-2 are equal (character for character), otherwise
  669. it expands to NOT-EQUAL.
  670.      ifelse(foo, bar, `true')
  671.      =>
  672.      ifelse(foo, foo, `true')
  673.      =>true
  674.      ifelse(foo, bar, `true', `false')
  675.      =>false
  676.      ifelse(foo, foo, `true', `false')
  677.      =>true
  678.    However, `ifelse' can take more than four arguments.  If given more
  679. than four arguments, `ifelse' works like a `case' or `switch' statement
  680. in traditional programming languages.  If STRING-1 and STRING-2 are
  681. equal, `ifelse' expands into EQUAL, otherwise the procedure is repeated
  682. with the first three arguments discarded.  This calls for an example:
  683.      ifelse(foo, bar, `third', gnu, gnats, `sixth', `seventh')
  684.      =>seventh
  685.    Naturally, the normal case will be slightly more advanced than these
  686. examples.  A common use of `ifelse' is in macros implementing loops of
  687. various kinds.
  688. File: m4.info,  Node: Loops,  Prev: Ifelse,  Up: Conditionals
  689. Loops and recursion
  690. ===================
  691.    There is no direct support for loops in `m4', but macros can be
  692. recursive.  There is no limit on the number of recursion levels, other
  693. than those enforced by your hardware and operating system.
  694.    Loops can be programmed using recursion and the conditionals
  695. described previously.
  696.    There is a built-in macro, `shift', which can, among other things,
  697. be used for iterating through the actual arguments to a macro:
  698.      shift(...)
  699. It takes any number of arguments, and expands to all but the first
  700. argument, separated by commas, with each argument quoted.
  701.      shift(bar)
  702.      =>
  703.      shift(foo, bar, baz)
  704.      =>bar,baz
  705.    An example of the use of `shift' is this macro, which reverses the
  706. order of its arguments:
  707.      define(`reverse', `ifelse($#, 0, , $#, 1, ``$1'',
  708.                    `reverse(shift($@)), `$1'')')
  709.      =>
  710.      reverse
  711.      =>
  712.      reverse(foo)
  713.      =>foo
  714.      reverse(foo, bar, gnats,and gnus)
  715.      =>and gnus, gnats, bar, foo
  716.    While not a very interesting macro, it does show how simple loops
  717. can be made with `shift', `ifelse' and recursion.
  718.    Here is an example of a loop macro that implements a simple forloop.
  719.  It can, for example, be used for simple counting:
  720.      forloop(`i', 1, 8, `i ')
  721.      =>1 2 3 4 5 6 7 8
  722.    The arguments are a name for the iteration variable, the starting
  723. value, the final value, and the text to be expanded for each iteration.
  724.  With this macro, the macro `i' is defined only within the loop.  After
  725. the loop, it retains whatever value it might have had before.
  726.    For-loops can be nested, like
  727.      forloop(`i', 1, 4, `forloop(`j', 1, 8, `(i, j) ')
  728.      ')
  729.      =>(1, 1) (1, 2) (1, 3) (1, 4) (1, 5) (1, 6) (1, 7) (1, 8)
  730.      =>(2, 1) (2, 2) (2, 3) (2, 4) (2, 5) (2, 6) (2, 7) (2, 8)
  731.      =>(3, 1) (3, 2) (3, 3) (3, 4) (3, 5) (3, 6) (3, 7) (3, 8)
  732.      =>(4, 1) (4, 2) (4, 3) (4, 4) (4, 5) (4, 6) (4, 7) (4, 8)
  733.      =>
  734.    The implementation of the `forloop' macro is fairly straightforward.
  735.  The `forloop' macro itself is simply a wrapper, which saves the
  736. previous definition of the first argument, calls the internal macro
  737. `_forloop', and re-establishes the saved definition of the first
  738. argument.
  739.    The macro `_forloop' expands the fourth argument once, and tests to
  740. see if it is finished.  If it has not finished, it increments the
  741. iteration variable (using the predefined macro `incr' (*note Incr::.
  742. for details)), and recurses.
  743.    Here is the actual implementation of `forloop':
  744.      define(`forloop',
  745.             `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')')
  746.      define(`_forloop',
  747.             `$4`'ifelse($1, `$3', ,
  748.                 `define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')')
  749.    Notice the careful use of quotes.  Only three macro arguments are
  750. unquoted, each for its own reason.  Try to find out *why* these three
  751. arguments are left unquoted, and see what happens if they are quoted.
  752.    Now, even though these two macros are useful, they are still not
  753. robust enough for general use. They lack even basic error handling of
  754. cases like start value less than final value, and the first argument
  755. not being a name.  Correcting these errors are left as an exercise to
  756. the reader.
  757. File: m4.info,  Node: Debugging,  Next: Input Control,  Prev: Conditionals,  Up: Top
  758. How to debug macros and input
  759. *****************************
  760.    When writing macros for `m4', most of the time they won't work as
  761. intended (as is the case with most programming languages).  There is a
  762. little support for macro debugging in `m4'.
  763. * Menu:
  764. * Dumpdef::                     Displaying macro definitions
  765. * Trace::                       Tracing macro calls
  766. * Debug Levels::                Controlling debugging output
  767. * Debug Output::                Saving debugging output
  768. File: m4.info,  Node: Dumpdef,  Next: Trace,  Prev: Debugging,  Up: Debugging
  769. Displaying macro definitions
  770. ============================
  771.    If you want to see what a name expands into, you can use the built-in
  772. `dumpdef':
  773.      dumpdef(...)
  774. which accepts any number of arguments.  If called without any arguments,
  775. it displays the definitions of all known names, otherwise it displays
  776. the definitions of the names given.  The output is printed directly on
  777. the standard error output.
  778.    The expansion of `dumpdef' is void.
  779.      define(`foo', `Hello world.')
  780.      =>
  781.      dumpdef(`foo')
  782.      error-->foo:    `Hello world.'
  783.      =>
  784.      dumpdef(`define')
  785.      error-->define:    <define>
  786.      =>
  787.    The last example shows how built-in macros definitions are displayed.
  788.    *Note Debug Levels:: for information on controlling the details of
  789. the display.
  790. File: m4.info,  Node: Trace,  Next: Debug Levels,  Prev: Dumpdef,  Up: Debugging
  791. Tracing macro calls
  792. ===================
  793.    It is possible to trace macro calls and expansions through the
  794. built-ins `traceon' and `traceoff':
  795.      traceon(...)
  796.      traceoff(...)
  797. When called without any arguments, `traceon' and `traceoff' will turn
  798. tracing on and off, respectively,  for all defined macros. When called
  799. with arguments, only the named macros are affected.
  800.    The expansion of `traceon' and `traceoff' is void.
  801.    Whenever a traced macro is called and the arguments have been
  802. collected, the call is displayed.  If the expansion of the macro call
  803. is not void, the expansion can be displayed after the call.  The output
  804. is printed directly on the standard error output.
  805.      define(`foo', `Hello World.')
  806.      =>
  807.      define(`echo', `$@')
  808.      =>
  809.      traceon(`foo', `echo')
  810.      =>
  811.      foo
  812.      error-->m4trace: -1- foo -> `Hello World.'
  813.      =>Hello World.
  814.      echo(gnus, and gnats)
  815.      error-->m4trace: -1- echo(`gnus', `and gnats') -> ``gnus',`and gnats''
  816.      =>gnus,and gnats
  817.    The number between dashes is the depth of the expansion.  It is one
  818. most of the time, signifying an expansion at the outermost level, but it
  819. increases when macro arguments contain unquoted macro calls.
  820.    *Note Debug Levels:: for information on controlling the details of
  821. the display.
  822. File: m4.info,  Node: Debug Levels,  Next: Debug Output,  Prev: Trace,  Up: Debugging
  823. Controlling debugging output
  824. ============================
  825.    The `-d' option to `m4' controls the amount of details presented,
  826. when using the macros described in the preceding sections.
  827.    The FLAGS following the option can be one or more of the following:
  828.      Trace all macro calls made in this invocation of `m4'.
  829.      Show the actual arguments in each macro call.  This applies to all
  830.      macro calls if the `t' flag is used, otherwise only the macros
  831.      covered by calls of `traceon'.
  832.      Show the expansion of each macro call, if it is not void.  This
  833.      applies to all macro calls if the `t' flag is used, otherwise only
  834.      the macros covered by calls of `traceon'.
  835.      Quote actual arguments and macro expansions in the display with the
  836.      current quotes.
  837.      Show several trace lines for each macro call.  A line is shown
  838.      when the macro is seen, but before the arguments are collected; a
  839.      second line when the arguments have been collected and a third
  840.      line after the call has completed.
  841.      Add a unique `macro call id' to each line of the trace output. 
  842.      This is useful in connection with the `c' flag above.
  843.      Show the name of the current input file in each trace output line.
  844.      Show the the current input line number in each trace output line.
  845.      Print a message when a named file is found through the path search
  846.      mecanism (*note Search Path::.), giving the actual filename used.
  847.      Print a message each time the current input file is changed,
  848.      giving file name and input line number.
  849.      A shorthand for all of the above flags.
  850.    If no flags are specified with the `-d' option, the default is
  851. `aeq'. The examples in the previous two sections assumed the default
  852. flags.
  853.    There is a built-in macro `debugmode', which allows on-the-fly
  854. control of the debugging output format:
  855.      debugmode(opt FLAGS)
  856. The argument FLAGS should be a subset of the letters listed above. As
  857. special cases, if the argument starts with a `+', the flags are added
  858. to the current debug flags, and if it starts with a `-', they are
  859. removed.  If no argument is present, the debugging flags are set to
  860. zero (as if no `-d' was given), and with an empty argument the flags
  861. are reset to the default.
  862. File: m4.info,  Node: Debug Output,  Prev: Debug Levels,  Up: Debugging
  863. Saving debugging output
  864. =======================
  865.    Debug and tracing output can be redirected to files using either the
  866. `-o' option to `m4', or with the built-in macro `debugfile':
  867.      debugfile(opt FILENAME)
  868. will send all further debug and trace output to FILENAME.  If FILENAME
  869. is empty, debug and trace output are discarded and if `debugfile' is
  870. called without any arguments, debug and trace output are sent to the
  871. standard error output.
  872. File: m4.info,  Node: Input Control,  Next: File Inclusion,  Prev: Debugging,  Up: Top
  873. Input control
  874. *************
  875.    This chapter describes various built-in macros for controlling the
  876. input to `m4'.
  877. * Menu:
  878. * Dnl::                         Deleting whitespace in input
  879. * Changequote::                 Changing the quote characters
  880. * Changecom::                   Changing the comment delimiters
  881. * M4wrap::                      Saving input until end of input
  882. File: m4.info,  Node: Dnl,  Next: Changequote,  Prev: Input Control,  Up: Input Control
  883. Deleting whitespace in input
  884. ============================
  885.    The built-in `dnl' reads and discards all characters, up to and
  886. including the first newline:
  887.      dnl
  888. and it is often used in connection with `define', to remove the newline
  889. that follow the call to `define'.  Thus
  890.      define(`foo', `Macro `foo'.')dnl A very simple macro, indeed.
  891.      foo
  892.      =>Macro foo.
  893.    The input up to and including the next newline is discarded, as
  894. opposed to the way comments are treated (*note Comments::.).
  895.    Usually, `dnl' is immediately followed by an end of line or some
  896. other whitespace.  GNU `m4' will produce a warning diagnostic if `dnl'
  897. is followed by an open parenthesis.  In this case, `dnl' will collect
  898. and process all arguments, looking for a matching close parenthesis. 
  899. All predictable side effects resulting from this collection will take
  900. place.  `dnl' will return no output.  The input following the matching
  901. close parenthesis up to and including the next newline, on whatever
  902. line containing it, will still be discarded.
  903. File: m4.info,  Node: Changequote,  Next: Changecom,  Prev: Dnl,  Up: Input Control
  904. Changing the quote characters
  905. =============================
  906.    The default quote delimiters can be changed with the built-in
  907. `changequote':
  908.      changequote(opt START, opt END)
  909. where START is the new start-quote delimiter and END is the new
  910. end-quote delimiter.  If any of the arguments are missing, the default
  911. quotes (``' and `'') are used instead of the void arguments.
  912.    The expansion of `changequote' is void.
  913.      changequote([,])
  914.      =>
  915.      define([foo], [Macro [foo].])
  916.      =>
  917.      foo
  918.      =>Macro foo.
  919.    If no single character is appropriate, START and END can be of any
  920. length.
  921.      changequote([[,]])
  922.      =>
  923.      define([[foo]], [[Macro [[[foo]]].]])
  924.      =>
  925.      foo
  926.      =>Macro [foo].
  927.    Changing the quotes to the empty strings will effectively disable the
  928. quoting mechanism, leaving no way to quote text.
  929.      define(`foo', `Macro `FOO'.')
  930.      =>
  931.      changequote(,)
  932.      =>
  933.      foo
  934.      =>Macro `FOO'.
  935.      `foo'
  936.      =>`Macro `FOO'.'
  937.    There is no way in `m4' to quote a string containing an unmatched
  938. left quote, except using `changequote' to change the current quotes.
  939.    Neither quote string should start with a letter or `_' (underscore),
  940. as they will be confused with names in the input.  Doing so disables
  941. the quoting mechanism.
  942. File: m4.info,  Node: Changecom,  Next: M4wrap,  Prev: Changequote,  Up: Input Control
  943. Changing comment delimiters
  944. ===========================
  945.    The default comment delimiters can be changed with the built-in
  946. macro `changecom':
  947.      changecom(opt START, opt END)
  948. where START is the new start-comment delimiter and END is the new
  949. end-comment delimiter.  If any of the arguments are void, the default
  950. comment delimiters (`#' and newline) are used instead of the void
  951. arguments.  The comment delimiters can be of any length.
  952.    The expansion of `changecom' is void.
  953.      define(`comment', `COMMENT')
  954.      =>
  955.      # A normal comment
  956.      =># A normal comment
  957.      changecom(`/*', `*/')
  958.      =>
  959.      # Not a comment anymore
  960.      =># Not a COMMENT anymore
  961.      But: /* this is a comment now */ while this is not a comment
  962.      =>But: /* this is a comment now */ while this is not a COMMENT
  963.    Note how comments are copied to the output, much as it they were
  964. quoted strings.  If you want the text inside a comment expanded, quote
  965. the start comment delimiter.
  966.    Calling `changecom' without any arguments disables the commenting
  967. mechanism completely.
  968.      define(`comment', `COMMENT')
  969.      =>
  970.      changecom
  971.      =>
  972.      # Not a comment anymore
  973.      =># Not a COMMENT anymore
  974. File: m4.info,  Node: M4wrap,  Prev: Changecom,  Up: Input Control
  975. Saving input
  976. ============
  977.    It is possible to `save' some text until the end of the normal input
  978. has been seen.  Text can be saved, to be read again by `m4' when the
  979. normal input has been exhausted.  This feature is normally used to
  980. initiate cleanup actions before normal exit, e.g., deleting temporary
  981. files.
  982.    To save input text, use the built-in `m4wrap':
  983.      m4wrap(STRING, ...)
  984. which stores STRING and the rest of the arguments in a safe place, to
  985. be reread when end of input is reached.
  986.      define(`cleanup', `This is the `cleanup' actions.
  987.      ')
  988.      =>
  989.      m4wrap(`cleanup')
  990.      =>
  991.      This is the first and last normal input line.
  992.      =>This is the first and last normal input line.
  993.      ^D
  994.      =>This is the cleanup actions.
  995.    The saved input is only reread when the end of normal input is seen,
  996. and not if `m4exit' is used to exit `m4'.
  997.    It is safe to call `m4wrap' from saved text, but then the order in
  998. which the saved text is reread is undefined.  If `m4wrap' is not used
  999. recursively, the saved pieces of text are reread in the opposite order
  1000. in which they were saved (LIFO--last in, first out).
  1001. File: m4.info,  Node: File Inclusion,  Next: Diversions,  Prev: Input Control,  Up: Top
  1002. File inclusion
  1003. **************
  1004.    `m4' allows you to include named files at any point in the input.
  1005. * Menu:
  1006. * Include::                     Including named files
  1007. * Search Path::                 Searching for include files
  1008. File: m4.info,  Node: Include,  Next: Search Path,  Prev: File Inclusion,  Up: File Inclusion
  1009. Including named files
  1010. =====================
  1011.    There are two built-in macros in `m4' for including files:
  1012.      include(FILENAME)
  1013.      sinclude(FILENAME)
  1014. both of which cause the file named FILENAME to be read by `m4'.  When
  1015. the end of the file is reached, input is resumed from the previous
  1016. input file.
  1017.    The expansion of `include' and `sinclude' is therefore the contents
  1018. of FILENAME.
  1019.    It is an error for an `include'd file not to exist.  If you don't
  1020. want error messages about non-existent files, `sinclude' can be used to
  1021. include a file, if it exists, expanding to nothing if it does not.
  1022.      include(`no-such-file')
  1023.      =>
  1024.      error-->m4:30.include:2: can't open no-such-file: No such file or directory
  1025.      sinclude(`no-such-file')
  1026.      =>
  1027.    Assume in the following that the file `incl.m4' contains the lines:
  1028.      Include file start
  1029.      foo
  1030.      Include file end
  1031. Normally file inclusion is used to insert the contents of a file into
  1032. the input stream.  The contents of the file will be read by `m4' and
  1033. macro calls in the file will be expanded:
  1034.      define(`foo', `FOO')
  1035.      =>
  1036.      include(`incl.m4')
  1037.      =>Include file start
  1038.      =>FOO
  1039.      =>Include file end
  1040.      =>
  1041.    The fact that `include' and `sinclude' expand to the contents of the
  1042. file can be used to define macros that operate on entire files. Here is
  1043. an example, which defines `bar' to expand to the contents of `incl.m4':
  1044.      define(`bar', include(`incl.m4'))
  1045.      =>
  1046.      This is `bar':  >>>bar<<<
  1047.      =>This is bar:  >>>Include file start
  1048.      =>foo
  1049.      =>Include file end
  1050.      =><<<
  1051.    This use of `include' is not trivial, though, as files can contain
  1052. quotes, commas and parentheses, which can interfere with the way the
  1053. `m4' parser works.
  1054. File: m4.info,  Node: Search Path,  Prev: Include,  Up: File Inclusion
  1055. Searching for include files
  1056. ===========================
  1057.    GNU `m4' allows included files to be found in other directories than
  1058. the current working directory.
  1059.    If a file is not found in the current working directory, and the file
  1060. name is not absolute, the file will be looked for in a specified search
  1061. path.  First, the directories specified with the `-I' option will be
  1062. searched, in the order found on the command line.  Second, if the
  1063. `M4PATH' environment variable is set, it is expected to contain a
  1064. colon-separated list of directories, which will be searched in order.
  1065.    If the automatic search for include-files causes trouble, the `p'
  1066. debug flag (*note Debug Levels::.) can help isolate the problem.
  1067. File: m4.info,  Node: Diversions,  Next: Text handling,  Prev: File Inclusion,  Up: Top
  1068. Diverting and undiverting output
  1069. ********************************
  1070.    Diversions are a way of temporarily saving output.  The output of
  1071. `m4' can at any time be diverted to a temporary file, and be reinserted
  1072. into the output stream, "undiverted", again at a later time.
  1073.    Up to ten numbered diversions (numbered from 0 to 9) are supported in
  1074. `m4', of which diversion number 0 is the normal output stream.  The
  1075. number of available diversions can be increased with the `-N' option.
  1076. * Menu:
  1077. * Divert::                      Diverting output
  1078. * Undivert::                    Undiverting output
  1079. * Divnum::                      Diversion numbers
  1080. * Cleardiv::                    Discarding diverted text
  1081.